home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ohlutil.zip / SYSTEM.H < prev    next >
C/C++ Source or Header  |  1990-06-22  |  4KB  |  177 lines

  1. /* system-dependent definitions for fileutils programs.
  2.    Copyright (C) 1989, 1990 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 1, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* Include sys/types.h before this file.  */
  19.  
  20. #include <sys/stat.h>
  21.  
  22. #ifdef USG
  23. #include <sys/times.h>
  24. #else
  25. #include <sys/time.h>
  26. #endif
  27.  
  28. #ifdef _POSIX_SOURCE
  29. #include <unistd.h>
  30. #include <limits.h>
  31. #else
  32. #include <sys/param.h>
  33. #define _POSIX_PATH_MAX 255
  34. #define _POSIX_NAME_MAX 14
  35. #ifndef PATH_MAX
  36. #ifdef MAXPATHLEN
  37. #define PATH_MAX MAXPATHLEN
  38. #else
  39. #define PATH_MAX _POSIX_PATH_MAX
  40. #endif
  41. #endif
  42. #ifndef NAME_MAX
  43. #ifdef MAXNAMLEN
  44. #define NAME_MAX MAXNAMLEN
  45. #else
  46. #define NAME_MAX _POSIX_NAME_MAX
  47. #endif
  48. #endif
  49. #endif
  50.  
  51. /* Filesystem device blocksize. */
  52. #ifndef DEV_BSIZE
  53. #ifdef BSIZE
  54. #define DEV_BSIZE BSIZE
  55. #else
  56. #define DEV_BSIZE 512
  57. #endif
  58. #endif
  59.  
  60. #ifdef _POSIX_SOURCE
  61. #define major(dev)  (((dev) >> 8) & 0xff)
  62. #define minor(dev)  ((dev) & 0xff)
  63. #define makedev(maj, min)  (((maj) << 8) | (min))
  64. #else
  65. #ifdef USG
  66. #include <sys/sysmacros.h>
  67. #endif
  68. #endif
  69.  
  70. #ifdef _POSIX_SOURCE
  71. #include <utime.h>
  72. #else
  73. struct utimbuf
  74. {
  75.   long actime;
  76.   long modtime;
  77. };
  78. #endif
  79.  
  80. #if defined(USG) || defined(_POSIX_SOURCE)
  81. #include <string.h>
  82. #define index strchr
  83. #define rindex strrchr
  84. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  85.  
  86. #ifndef _POSIX_SOURCE
  87. /* Args for access. */
  88. #define F_OK 0
  89. #define X_OK 1
  90. #define W_OK 2
  91. #define R_OK 4
  92.  
  93. char *getcwd ();
  94. #endif
  95. #define getwd(buf) getcwd ((buf), PATH_MAX + 2)
  96.  
  97. /* Args for lseek. */
  98. #define L_SET 0
  99. #define L_INCR 1
  100. #define L_XTND 2
  101. #else
  102. #include <strings.h>
  103. #include <sys/file.h>
  104.  
  105. char *getwd ();
  106. #endif
  107.  
  108. #include <fcntl.h>
  109.  
  110. #ifdef DIRENT
  111. #include <dirent.h>
  112. #define direct dirent
  113. #define NLENGTH(direct) (strlen((direct)->d_name))
  114. #else
  115. #define NLENGTH(direct) ((direct)->d_namlen)
  116. #ifdef USG
  117. #ifdef SYSNDIR
  118. #include <sys/ndir.h>
  119. #else
  120. #include <ndir.h>
  121. #endif
  122. #else /* must be BSD */
  123. #include <sys/dir.h>
  124. #endif
  125. #endif
  126.  
  127. /* Extract data from a `struct stat'.
  128.    ST_BLKSIZE: Optimal I/O blocksize for the file.
  129.    ST_NBLOCKS: Number of blocks in the file (including indirect blocks). */
  130. #ifdef _POSIX_SOURCE
  131. #define ST_BLKSIZE(statbuf) DEV_BSIZE
  132. #define ST_NBLOCKS(statbuf) (((statbuf).st_size + DEV_BSIZE - 1) / DEV_BSIZE)
  133. #else
  134. #ifdef STBLOCKS_MISSING
  135. #define ST_BLKSIZE(statbuf) DEV_BSIZE
  136. #define ST_NBLOCKS(statbuf) (st_blocks ((statbuf).st_size))
  137. #else
  138. /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
  139. #define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
  140.                  ? (statbuf).st_blksize : DEV_BSIZE)
  141. #define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
  142. #endif
  143. #endif
  144.  
  145. /* Convert B blocks of DEV_BSIZE bytes
  146.    to kilobytes if K is nonzero, otherwise to blocks of 512 bytes. */
  147.  
  148. #if DEV_BSIZE == 512
  149. #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
  150. #else
  151. #if DEV_BSIZE == 1024
  152. #define convert_blocks(b, k) ((k) ? (b) : (b) * 2)
  153. #else
  154. #define convert_blocks(b, k) ((k) \
  155.                   ? ((b) * DEV_BSIZE + 1023) / 1024 \
  156.                   : ((b) * DEV_BSIZE + 511) / 512)
  157. #endif
  158. #endif
  159.  
  160. #ifndef S_IFLNK
  161. #define lstat stat
  162. #endif
  163.  
  164. #ifndef SIGTYPE
  165. #define SIGTYPE void
  166. #endif
  167.  
  168. #ifdef __GNUC__
  169. #define alloca __builtin_alloca
  170. #else
  171. #ifdef sparc
  172. #include <alloca.h>
  173. #else
  174. char *alloca ();
  175. #endif
  176. #endif
  177.